package com.example.service.impl;

import com.example.mapper.UserMapper;
import com.example.pojo.User;
import com.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * @program: springboot_course
 * @description:
 * @author: ChenZhiXiang
 * @create: 2019-06-12 17:38
 **/
@Service
@CacheConfig(cacheNames = {"users"})
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @CacheEvict(key = "'user_getUserList'")
    @Override
    public void delete(Integer id) {
        userMapper.delete(id);
    }

    @CacheEvict(key = "'user_getUserList'")
    @Override
    public User update(User user) {
        return userMapper.update(user);
    }

    @Override
    public User findById(Integer id) {
        return userMapper.findById(id);
    }

    @Cacheable(key = "'user_getUserList'")
    @Override
    public List<User> getUserList() {
        return userMapper.getUserList();
    }

    @CacheEvict(key = "'user_getUserList'")
    @Override
    public int save(User user) {
        int i = userMapper.save(user);
        return user.getId();
    }
}
